package fr.ul.ade.prime.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * @author Zanette Sébastien, Schnell Michaël
 */
public class Project implements Parcelable {

	private long id;

	private int adeProjectId;

	private String projectName;

	private boolean isLoaded;

	public Project() {
		super();
	}

	/**
	 * @param textId
	 */
	public Project(long id, int adeProjectId, String projectName) {
		this(adeProjectId, projectName);
		this.id = id;
	}

	/**
	 * @param textId
	 */
	public Project(int adeProjectId, String projectName) {
		this.adeProjectId = adeProjectId;
		this.projectName = projectName;
		this.isLoaded = true;
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return this.id;
	}

	/**
	 * @return the projectName
	 */
	public String getProjectName() {
		return this.projectName;
	}

	/**
	 * @return the adeProjectId
	 */
	public int getAdeProjectId() {
		return this.adeProjectId;
	}

	public boolean isLoaded() {
		return this.isLoaded;
	}

	public void setLoaded(int isLoaded) {
		this.isLoaded = (isLoaded == 1 ? true : false);
	}

	public void setAdeProjectId(int adeProjectId) {
		this.adeProjectId = adeProjectId;
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof Project) {
			Project other = (Project) o;
			return (this.id == other.id);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return Long.valueOf(this.id).hashCode();
	}

	@Override
	public String toString() {
		return String.format("'%s' - ade: %d (id: %d)", this.projectName, //$NON-NLS-1$
				this.adeProjectId, this.id);
	}

	public static final Parcelable.Creator<Project> CREATOR = new Creator<Project>() {

		@Override
		public Project[] newArray(int size) {
			return new Project[size];
		}// newArray(int)

		@Override
		public Project createFromParcel(Parcel source) {
			long id = source.readLong();
			int adeId = source.readInt();
			String name = source.readString();
			return new Project(id, adeId, name);
		}// createFromParcel(Parcel)

	};

	@Override
	public int describeContents() {
		return 0;
	}// describeContents()

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeLong(this.id);
		dest.writeInt(this.adeProjectId);
		dest.writeString(this.projectName);
	}// writeToParcel(Parcel, int)

}// class Project